package com.xinghen.ace.common.model;

import com.xinghen.ace.common.constant.CommonConstants;
import lombok.Data;

import java.util.LinkedHashMap;
import java.util.Map;

/**
 * @author xinghen
 * @ClassName: Query
 * @Package: com.xinghen.ace.common.model
 * @Description 查询参数
 * @create 2018/5/3 17:47
 */
@Data
public class Query extends LinkedHashMap<String, Object> {

    /**
     * 当前页码
     */
    private int page = 1;

    /**
     * 每页条数
     */
    private int limit = 10;

    public Query(Map<String, Object> params) {
        this.putAll(params);
        //分页参数
        if (params.get(CommonConstants.PAGE_KEY) != null) {
            this.page = Integer.parseInt(params.get(CommonConstants.PAGE_KEY).toString());
        }
        if (params.get(CommonConstants.LIMIT_KEY) != null) {
            this.limit = Integer.parseInt(params.get(CommonConstants.LIMIT_KEY).toString());
        }
        this.remove(CommonConstants.PAGE_KEY);
        this.remove(CommonConstants.LIMIT_KEY);
    }

}
